package com.health.memberbackstage.web;

import com.health.memberbackstage.pojo.Appointment;
import com.health.memberbackstage.pojo.R.Result;
import com.health.memberbackstage.pojo.R.ResultEnum;
import com.health.memberbackstage.service.AppointmentService;
import com.health.memberbackstage.utils.AuthenticationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/appointment")
public class AppointmentController {

    @Autowired
    private AppointmentService appointmentService;

    @PostMapping
    @Transactional
    public Result addAppointment(@RequestBody Appointment appointment){
        Long memberID = AuthenticationUtils.getMemberID();
        appointment.setMemberId(memberID);
        boolean flag = appointmentService.save(appointment);
        if (flag){
            return Result.success();
        }
        return Result.fail(ResultEnum.FAILED_ADD);
    }
}